package com.xxxx.server.controller;


import com.xxxx.server.rest.RespBean;
import com.xxxx.server.pojo.Salary;
import com.xxxx.server.service.impl.SalaryServiceImpl;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zhoubin
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/salary/sob/")
public class SalaryController {

    @Autowired
    private SalaryServiceImpl salaryService;


    //查询操作
    @ApiOperation(value = "部门工资的查询")
    @GetMapping("/")
    public List<Salary> initSalaries(){
        return  salaryService.list();
    }

    //添加操作
    @ApiOperation(value = "部门工资的添加")
    @PostMapping("/")
    public RespBean addSalay(@RequestBody Salary salary){
        salary.setCreateDate(LocalDateTime.now());
        if (salaryService.save(salary)){
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }

    //修改操作
    @ApiOperation(value = "部门工资的修改")
    @PutMapping("/")
    public RespBean updateSalay(@RequestBody Salary salary){

        if (salaryService.updateById(salary)){
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }

    //删除操作
    @ApiOperation(value = "部门工资的删除")
    @DeleteMapping("/{id}")
    public RespBean deleteSalay(@PathVariable Integer id){

        if (salaryService.removeById(id)){
            return RespBean.success("success");
        } else {
            return RespBean.error("fail");
        }
    }
}
